<?php


namespace App\Http\Controllers\admin;

use App\Dao\ImagesDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;
use App\Validate\Logic\ImagesLogic;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;

/**
 * Class ImagesController
 * @package App\Http\Controllers\admin
 * author:fhc
 * desc:l怒波图控制器
 * created_at: 2020/11/19 - 1:01 下午
 */
class ImagesController extends BaseController
{
    /**
     * author:fhc
     * desc:主方法
     * created_at: 2020/11/19 - 1:02 下午
     */
    public function index(){
        if(getIsHasPage()){
            return Code::message('',200,ImagesDao::getImagesPager());
        }

        return view('admin.images.images');
    }


    /**
     * author:fhc
     * desc:添加图片
     * created_at: 2020/11/20 - 7:27 下午
     * @param ImagesLogic $logic
     * @return array|Application|Factory|View
     * @throws SysExceptions
     */
    public function add(ImagesLogic $logic){
        if(isPost()){
            $all = request()->all();
            $logic->add($all);
            ImagesDao::add($all);
            return Code::message();
        }

        return view('admin.images.add');
    }


    /**
     * author:fhc
     * desc:编辑图片
     * created_at: 2020/11/20 - 8:01 下午
     * @param ImagesLogic $logic
     * @return array|Application|Factory|View
     * @throws SysExceptions
     */
    public function edit(ImagesLogic $logic){
        if(isPost()){
            $all = request()->all();
            $logic->update($all);
            ImagesDao::update($all);
            return Code::message();
        }

        return view('admin.images.edit',[
            'info'=>ImagesDao::getImagesBuilder([
                'id'=>request('id')
            ])->first()
        ]);
    }

}
